<!--
 * @Description: 
 * @Version: 2.0
 * @Autor: zhangjx
 * @Date: 2023-05-29 17:41:52
 * @LastEditors: uphldjx 1373577124@qq.com
 * @LastEditTime: 2023-09-25 09:48:22
-->
<template>
	<div>
		<AplidForm ref="formRef" v-bind="formConfig" v-model="formModel" @submit="onSubmit">
			<div class="fc">
				<el-button class="ap-btn" type="primary" @click="handleSubmit('submit-next')"> 保存并进入下一步 </el-button>
			</div>
		</AplidForm>
	</div>
</template>

<script setup lang="ts">
import { useCrudStore } from '@/stores/crud'
const { saveDictForm } = useCrudStore()
const emit = defineEmits(['refresh'])
const props = defineProps({
	nowRowData: Object,
})
const formRef = ref(null)
const formModel: any = ref(props.nowRowData || {})
const formConfig = {
	label: '字典信息',
	prop: 'base0',
	inline: false,
	showBtn: false,
	labelPosition: 'left',
	column: [
		{
			label: '字典名称',
			prop: 'dictName',
			type: 'text',
			maxlength: '100',
			showWordLimit: true,
			span: 24,
			rules: [{ required: true, message: '请输入字典名称' }],
		},
		{
			label: '字典标识',
			prop: 'identifying',
			type: 'text',
			maxlength: '50',
			showWordLimit: true,
			span: 24,
			rules: [{ required: true, message: '请输入字典标识' }],
		},
		{
			label: '字典描述',
			prop: 'description',
			type: 'textarea',
			maxlength: '140',
			showWordLimit: true,
			span: 24,
			rules: [{ required: true, message: '请输入字典描述' }],
		},
		{
			label: '字典类型',
			prop: 'type',
			type: 'remoteSelect',
			code: 'DICT_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 24,
			rules: [{ required: true, message: '请选择字典类型' }],
		},
	],
}

const onSubmit = (form, done) => {
	saveDictForm(form,true)
		.then((res) => {
			emit('refresh')
			done()
		})
		.catch(() => {
			done()
		})
}

const handleSubmit = (type) => {
	formRef.value.onSubmit()
}
</script>

<style scoped></style>
